//
//  OppiontmentViewController.m
//  HaierGMS_APP
//
//  Created by 堂堂 on 16/9/13.
//  Copyright © 2016年 堂堂. All rights reserved.
//

#import "OppiontmentViewController.h"
#import "UIColor+Hex.h"
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height//获取屏幕高度，兼容性测试
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width//获取屏幕宽度，兼容性测试
@interface OppiontmentViewController ()

@end

@implementation OppiontmentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor greenColor];//[UIColor colorWithHexString:@"f2f2f2"];
    //初始化数据
    [self initData];

    
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton * cancle = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 60, 30)];
    [cancle setTitle:@"取消" forState:UIControlStateNormal];
    cancle.titleLabel.font = [UIFont systemFontOfSize:13 ];
    [cancle setTitleColor:[UIColor colorWithHexString:@"#ff7e00"] forState:UIControlStateNormal];
    
    UIButton * ok = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 70, 10, 60, 30)];
    ok.titleLabel.font = [UIFont systemFontOfSize:13 ];
    [ok setTitle:@"确定" forState:UIControlStateNormal];
    [ok setTitleColor:[UIColor colorWithHexString:@"#ff7e00"] forState:UIControlStateNormal];
    

    UIPickerView *pickView1 = [[UIPickerView alloc]initWithFrame:CGRectMake(10, 40,(ScreenWidth - 20) , 200)];
    pickView1.backgroundColor = [UIColor greenColor];
    

    
//    for (int component = 0; component<self.dataArray.count; component++) {
//        [pickView1 selectRow:0 inComponent:component animated:NO];
//    }
    pickView1.dataSource = self;
    pickView1.delegate = self;
    
    pickView1.showsSelectionIndicator = YES;
    
    [pickView1 reloadAllComponents];
    
    [self.view addSubview:cancle];
    [self.view addSubview:ok];
    [self.view addSubview:pickView1];

  
    NSCalendar *calender = [NSCalendar currentCalendar];
    
    NSRange range = [calender rangeOfUnit:NSDayCalendarUnit
                     
                                   inUnit: NSYearCalendarUnit
                     
                                  forDate: [NSDate date]];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initData{
    NSDate * date = [NSDate date];
    NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSYearCalendarUnit;
    
    comps = [calendar components:unitFlags fromDate:date];
    
    int year = [comps year];
    
    NSArray * array1 = @[[NSString stringWithFormat:@"%i",year],[NSString stringWithFormat:@"%i",year + 1]];
    
    NSMutableArray *monthDay = [[NSMutableArray alloc]init];
    
    for (int i = 1; i <= 12; i++) {
        
        if (i == 4 || i == 6 || i == 9 || i == 11) {
            for (int j=1; j <= 30; j++) {
                [monthDay addObject:[NSString stringWithFormat:@"%i月%i日",i,j]];
            }
        }else if(i == 2){
            for (int j=1; j <= 31; j++) {
                [monthDay addObject:[NSString stringWithFormat:@"%i月%i日",i,j]];
            }
        }
    }
    NSMutableArray *timeArray = [[NSMutableArray alloc]init];

    
    for (int i = 0; i < 24; i++) {
        if (i == 0) {
            [timeArray addObject:[NSString stringWithFormat:@"00:00"]];
        }else{
            [timeArray addObject:[NSString stringWithFormat:@"%i:00",i]];
        }
         [timeArray addObject:[NSString stringWithFormat:@"%i:15",i]];
        
         [timeArray addObject:[NSString stringWithFormat:@"%i:30",i]];
         [timeArray addObject:[NSString stringWithFormat:@"%i:45",i]];
    }
    NSLog(@"%lu",array1.count);
    NSLog(@"%lu",monthDay.count);
    NSLog(@"%lu",timeArray.count);
   
    
    self.dataArray = @[array1,monthDay,timeArray];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    
    NSLog(@"numberOfComponentsInPickerView");
    return self.dataArray.count;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
     NSLog(@"numberOfRowsInComponent");
    NSArray * array = [self.dataArray objectAtIndex:component];
    
    return array.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
     NSLog(@"titleForRow%i==%i",component,row);
    NSArray * array = [self.dataArray objectAtIndex:component];
    
    NSString *s = [array objectAtIndex:row];
    NSLog(@"s==%@",s);
    return s;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSLog(@"%@",self.dataArray[component][row]);
}

//- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
//{
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12.0f, 0.0f, [pickerView rowSizeForComponent:component].width - 12, [pickerView rowSizeForComponent:component].height)] ;
//    
//    label.text = self.dataArray[component][row];
//    label.backgroundColor = [UIColor clearColor];
//    label.textColor = [UIColor blackColor];
//    //[label setTextAlignment:UITextAlignmentCenter];
//    return label;
//}

#pragma mark-隐藏状态栏
 -(BOOL)prefersStatusBarHidden
{
 return YES;
 }
@end
